import RedisHelper
import MysqlHelper
import hashlib

name=input("请输入用户名：")
pwd=input("请输入密码：")

sha1=hashlib.sha1()
sha1.update(pwd)
pwd1=sha1.hexdigest()

try:
    redis=RedisHelper()
    if redis.get('uname')==name:
        print 'ok'
    else:
        mysql=MysqlHelper('localhost',3306,'test1','root','ut123456')
        upwd=mysql.get_one('select upwd from userinfos where uname=%s',[name])
        if upwd==None:
            print('用户名错误')
        elif upwd[0]==pwd1:
            redis.set('uname', name)
            print('登录成功')
        else:
            print("密码错误")

except Exception as e:
    print(e.message)